'use strict';

angular.module('Help').controller('SocketController',
    ['$scope', '$resource', '$stateParams', 'PublicFunction', 'PublicSocket', '$location', 'Authentication',
    function($scope, $resource, $stateParams, PublicFunction, PublicSocket, $location, Authentication) {
    	$scope.message = '';
		$scope.messages = [];

		PublicSocket.on('news',function(data) {
			$scope.messages.push(data.message);
			$scope.$digest();
		});

		PublicSocket.on('msg',function(data) {
			$scope.messages.push(data.message);
			$scope.$digest();
		});

		$scope.btnSend = function(){
			PublicSocket.toAll('msg', {message:$scope.message});
			$scope.message = '';
		};

		$scope.btnOut = function(){
			PublicSocket.removeListener('chatMessage');
		};
    }
]);